import { request } from "../../utils/request.js";
import regeneratorRuntime from "../../utils/runtime.js";
var bsurl = require('../../utils/bsurl.js');
Page({
  data: {
    inpValuePhone:'',
    inpValuePassword:''
  },
  handleInputPhone(e){
    const {value}=e.detail;
    this.setData({
      inpValuePhone:value
    })
  },
  handleInputPassword(e){
    const {value}=e.detail;
    this.setData({
      inpValuePassword:value
    });
  },
  async handelLogin(){
    const {inpValuePhone}=this.data;
    const {inpValuePassword}=this.data;
    const info=await request({url: bsurl+'login/cellphone?phone='+inpValuePhone+'&password='+inpValuePassword});
    if(info.code===400){
      wx.showToast({
        title: '请输入正确的账号',
        icon: 'none',
        success: (result) => {
          this.setData({
            inpValuePhone:''
          })          
        },
      });       
    }
    else if(info.code===502){
      wx.showToast({
        title: '密码错误',
        icon: 'none',
        success: (result) => {
          this.setData({
            inpValuePassword:''
          })      
        },
      });   
    }
    else if(info.code===200){
      wx.showToast({
        title: '登录成功',
        icon: 'success',
        success: (result) => {
          const userinfo=info.profile;
          wx.setStorageSync('userinfo', userinfo);
          wx.switchTab({
            url: '../home/index',
          });          
        },
      });    
    }
  },
})